// 获取输入框
let dom = document.getElementById('inputdom')
// 获取按钮
let openPage = document.getElementById('openPage')
let analysis = document.getElementById('analysis')
let currentPage = document.getElementById('currentPage')

// 开启解析
function analysisFun(data) {
  chrome.runtime.sendMessage(data)
}

// 通知消息
function notificationsFun(message,title,icon) {
  const { notifications } = chrome
  notifications.create({
    type: "basic",
    title: title,
    message: message,
    iconUrl: `images/${icon}.png`
  })
}

// 打开解析页面
openPage.onclick = function () {
  analysisFun({
    type: 'openPage',
  })
  // 处理通知
  notificationsFun('启动成功！', 'successful', 'successful')
  return null
}

//直接解析-并打开
analysis.onclick = function () {
  let value = dom.value.trim()
  if (!value) {
    notificationsFun('请输入需要解析的视频地址', 'error', 'failure')
    return null
  }
  let str=new RegExp("http")
  let flag = str.test(value)
  if(!flag) {
    notificationsFun('解析地址输入有误～', 'error', 'failure')
    return null
  }
  analysisFun({
    type: 'analysis',
    value: value,
  })
  // 处理通知
  notificationsFun('启动成功！', 'successful', 'successful')
  return null
}

//解析当前页面
currentPage.onclick = function () {
  analysisFun({
    type: 'currentPage',
  })
  // 处理通知
  notificationsFun('启动成功！', 'successful', 'successful')
  return null
}




